import "package:flutter/material.dart";

import '../../common/my_icon.dart';
import '../../components/dialog/exit_dialog.dart';

/// AppBar
class AppBarWidget {
  String _title;
  double _elevation;
  bool _centerTitle;
  bool _isMore;
  List<Widget> _actionsLW;

  AppBarWidget(
    String title, {
    double elevation = 0.0,
    bool centerTitle = false,
    bool isMore = true,
    List<Widget> actionsLW = null,
  }) {
    this._title = title;
    this._elevation = elevation;
    this._centerTitle = centerTitle;
    this._isMore = isMore;
    this._actionsLW = actionsLW;
  }

  /// 构建AppBar
  PreferredSizeWidget build(BuildContext context, {List<Widget> operListBtn}) {
    if (_isMore) {
      return _rightMore(context);
    } else {
      return _nomore(context);
    }
  }

  /// 没有“更多”操作
  AppBar _nomore(context) {
    return AppBar(
      title: Text(
        _title,
        style: TextStyle(fontSize: 18),
      ),
      elevation: _elevation,
      centerTitle: _centerTitle,
    );
  }

  /// 右侧带操作按钮
  AppBar _rightMore(context) {
    return AppBar(
      title: Text(
        _title,
        style: TextStyle(fontSize: 18),
      ),
      elevation: _elevation,
      centerTitle: _centerTitle,
      actions: [
        IconButton(
          icon: Icon(
            MyIcon.exit,
            size: 20,
          ),
          onPressed: () => ExitDialog.exit(context),
        ),
      ],
    );
  }
}
